package com.fx.jhr.controller;

import com.fx.jhr.domain.XsJhr;
import com.fx.jhr.service.IXsJhrService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学生监护人Controller
 *
 * @author fxiao
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/fx/jhr")
public class XsJhrController extends BaseController
{
    @Autowired
    private IXsJhrService xsJhrService;

    /**
     * 查询学生监护人列表
     */
    @PreAuthorize("@ss.hasPermi('fx:jhr:list')")
    @GetMapping("/list")
    public TableDataInfo list(XsJhr xsJhr)
    {
        startPage();
        List<XsJhr> list = xsJhrService.selectXsJhrList(xsJhr);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('fx:jhr:list')")
    @GetMapping("jhr/student/{studentid}")
    public List<XsJhr>selectByStudent(@PathVariable("studentid") Long studentid){
        List<XsJhr> xsJhrList=xsJhrService.selectByStudent(studentid);
        return xsJhrList;
    }

    /**
     * 导出学生监护人列表
     */
    @PreAuthorize("@ss.hasPermi('fx:jhr:export')")
    @Log(title = "学生监护人", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(XsJhr xsJhr)
    {
        List<XsJhr> list = xsJhrService.selectXsJhrList(xsJhr);
        ExcelUtil<XsJhr> util = new ExcelUtil<XsJhr>(XsJhr.class);
        return util.exportExcel(list, "jhr");
    }

    /**
     * 获取学生监护人详细信息
     */
    @PreAuthorize("@ss.hasPermi('fx:jhr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(xsJhrService.selectXsJhrById(id));
    }

    /**
     * 新增学生监护人
     */
    @PreAuthorize("@ss.hasPermi('fx:jhr:add')")
    @Log(title = "学生监护人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XsJhr xsJhr)
    {
        return toAjax(xsJhrService.insertXsJhr(xsJhr));
    }

    /**
     * 修改学生监护人
     */
    @PreAuthorize("@ss.hasPermi('fx:jhr:edit')")
    @Log(title = "学生监护人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XsJhr xsJhr)
    {
        return toAjax(xsJhrService.updateXsJhr(xsJhr));
    }

    /**
     * 删除学生监护人
     */
    @PreAuthorize("@ss.hasPermi('fx:jhr:remove')")
    @Log(title = "学生监护人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xsJhrService.deleteXsJhrByIds(ids));
    }
}
